from page.net_project_page import NetProjectPage
from page.common_tools import CommonTools
from common.page import IOS, XPATH
import random as r
import time as t


today = t.strftime('%Y%m%d', t.localtime(t.time()))


class NetCommPage(NetProjectPage, CommonTools):
    # 交流详情页面
    comment_text = (XPATH, '//XCUIElementTypeStaticText[@name="请输入内容"]/../XCUIElementTypeTextView')

    def release_comm(self, title='%s自动化测试交流%d' % (today, r.randint(100, 999))):
        self.find_button("common release").click()
        self.find_static_text(string="请输入标题",contains_flag=1).click()
        self.find_static_text(string="请输入标题",contains_flag=1).send_keys(title)
        self.find_button("完成").click()
        # self.find_element(XPATH,"//XCUIElementTypeTextField[contains(@value,'请输入标题')]").send_keys(title)
        # self.find_element(XPATH, "//XCUIElementTypeTextView[contains(@value,'请输入内容')]").send_keys('这是交流的内容。他敢于践踏任何美好的东西，包括爱情、友谊、荣誉，而且内心没有丝毫不安。这样的人尽管有再多的艳遇，也没有能力真正爱一回；结交再多的哥们，也体味不了友谊的纯正；获取再多的名声，也不知什么是光荣。不相信神圣 的人，必被世上一切神圣的事物所抛弃。。。。。')
        self.swipe(20,150,20,150)
        self.Edit_all()   #内容编辑

        # self.get_frame_center_and_click((IOS, 'type == "XCUIElementTypeButton" AND label == "附件"'))
        # self.find_button("xiangji").click()
        self.find_element(XPATH, "//XCUIElementTypeOther/XCUIElementTypeButton[1]").click()  # 附件
        self.find_element(XPATH, "//XCUIElementTypeCell[2]/XCUIElementTypeOther[1]").click()  # 相机

        self.take_ptoto()
        t.sleep(1)
        self.find_button("下一步").click()
        self.find_static_text("公开方式").click()
        self.find_button("确定").click()
        t.sleep(1)
        self.find_button("commontool review unselected").click()
        self.find_button("我同意").click()
        self.find_button("发布").click()
        t.sleep(2)

    def enter_comm(self, tit ='学生交流草稿标题%d' % (r.random())):
        # self.find_element(IOS, 'type == "XCUIElementTypeStaticText" AND label CONTAINS "%s"' % title).click()
        self.find_button("发布").click()
        self.find_static_text(string="请输入标题", contains_flag=1).click()
        self.find_static_text(string="请输入标题", contains_flag=1).send_keys(tit)
        self.find_button("完成").click()

        self.swipe(20, 150, 20, 150)
        t.sleep(2)
        self.find_element(XPATH,"//XCUIElementTypeOther/XCUIElementTypeTextView").send_keys("故事似乎要结束了，如果没有那封信的话。那封信是他临终前交给她的：“原谅我一直都欺骗了你，还记得四十年前我们相识时我很难受，也很紧张，不知怎么想的，竟然对小姐说拿些盐来")
        self.hide_keyboard()
        self.find_button("common back dark icon").click()
        self.find_button("保存草稿").click()
        t.sleep(3)
        self.find_element(XPATH, "//XCUIElementTypeStaticText[contains(@label,'我发布的')]").click()
        self.find_static_text(string="我的草稿", contains_flag=1).click()
        self.find_button(string="返回",contains_flag=1).click()
        t.sleep(1)
        self.find_button(string="common back light icon",contains_flag=1).click()


    def view_comment_comm(self, title='自动化测试交流'):
        self.swipe_dr('down')
        t.sleep(3)
        self.find_element(IOS, 'type == "XCUIElementTypeStaticText" AND label CONTAINS "%s"' % title).click()
        self.swipe(20,696,20,696)
        # self.get_frame_center_and_click(self.find_text_field(string="发布评论", attr='value'), flag=0)
        self.find_element(XPATH,"//XCUIElementTypeOther/XCUIElementTypeTextView").send_keys('这是评论的内容。相反，那种不知敬畏的人是从肆。只要不受惩罚，他敢于践踏任何美好的东西，包括爱情、友谊、荣誉，而且内心也没有能力真正爱一回；结交再多的哥们，也体味不了友谊的纯正；获取再多的名声，也么，这种人因为不知耻便显出一种卑怯的放肆。只要不受惩罚，')
        t.sleep(3)
        self.find_button("发布").click()
        self.find_button("smore").click()
        self.find_button("编辑").click()
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button("确定").click()
        self.find_button(string="common back dark icon", contains_flag=1).click()
        t.sleep(2)
        self.Select_btn()
        self.find_button("commontool review unselected").click()
        self.find_button("我同意").click()
        self.find_button("更新草稿").click()
        t.sleep(3)
        self.find_static_text("删除").click()
        self.find_button("确定").click()
        self.find_button(string="common back dark icon",contains_flag=1).click()
        t.sleep(1)
        self.find_button(string="common back light icon",contains_flag=1).click()


if __name__ == '__main__':
    test = NetCommPage()
    test.enter_project()
    test.enter_tools('交流')
    test.release_comm()
    test.view_comment_comm()
